namespace Beauty.Net.Consul.Core;

/// <summary>
/// Consul服务发现接口
/// </summary>
public interface IConsulDiscoveryService
{
    /// <summary>
    /// 获取所有服务实例
    /// </summary>
    Task<List<ServiceInstance>> GetAllServicesAsync(CancellationToken cancellationToken = default);
    
    /// <summary>
    /// 根据服务名称获取服务实例
    /// </summary>
    Task<List<ServiceInstance>> GetServicesAsync(string serviceName, CancellationToken cancellationToken = default);
    
    /// <summary>
    /// 随机获取一个可用的服务实例
    /// </summary>
    Task<ServiceInstance?> GetRandomServiceAsync(string serviceName, CancellationToken cancellationToken = default);
    
    /// <summary>
    /// 检查服务是否健康
    /// </summary>
    Task<bool> IsServiceHealthyAsync(string serviceId, CancellationToken cancellationToken = default);
}

/// <summary>
/// 服务实例模型
/// </summary>
public class ServiceInstance
{
    /// <summary>
    /// 服务ID
    /// </summary>
    public string ServiceId { get; set; } = string.Empty;
    
    /// <summary>
    /// 服务名称
    /// </summary>
    public string ServiceName { get; set; } = string.Empty;
    
    /// <summary>
    /// 服务地址
    /// </summary>
    public string Address { get; set; } = string.Empty;
    
    /// <summary>
    /// 服务端口
    /// </summary>
    public int Port { get; set; }
    
    /// <summary>
    /// 服务标签
    /// </summary>
    public List<string> Tags { get; set; } = new List<string>();
    
    /// <summary>
    /// 是否健康
    /// </summary>
    public bool IsHealthy { get; set; }
    
    /// <summary>
    /// 获取完整的服务URL
    /// </summary>
    public string ServiceUrl => $"http://{Address}:{Port}";
}